home *** CD-ROM | disk | FTP | other *** search
- Unit LIBACCES;
- {$I-}
- Interface
-
- Uses Dos,StrTool,Geddefs;
-
- Const Max_Lib_Size=255;
-
- LIB_FILEID ='DYLIB510';
-
- Type Dir_Entry =Record
- Case Word of
- 1: {alle Verzeichnis-Einträge(Index 1..N) }
- (Macroname :NameStr;
- NrOfRecs :Word;
- FileOffset:Longint; { für Seek }
- Date :Longint);
- 0: {Nur Verzeichnis-Eintrag 0 }
- (FILEID :NameStr;
- NrOfDirEntries :Word;
- UsedBLDRecs:Longint; { Anzahl gültigen BLD-Records in Benutzung }
- TotalSize :Longint); { Anzahl der BLD-Records ohne DIR-Size }
- end;
- Const
- Dir_Header_Size=(Sizeof(Dir_Entry)*(Max_Lib_Size+1)) div SizeOf(BildElement);
- { Größe des Directory-Headers in Bildelementen }
-
- Type
- Dir_Table =Array[0..Max_Lib_Size] of Dir_Entry;
-
- Dir_Buffer=Record
- Case Boolean of
- true:(DIR:Dir_table);
- false:(HEADER:Array[0..Dir_Header_Size] of Bildelement);
- end;
-
- Function Find_In_Dir(Name:NameStr;Var Verz:Dir_Table):Word;
- { 0 , wenn nicht gefunden, index in DIR-TABLE wenn gefunden }
-
- Function Get_Dir_Buff(Var F:File;Var DirBuff:Dir_Buffer):Boolean;
- { liest Dir-Buffer einer Datei, und öffnet Datei}
-
- Function Put_Dir_Buff(Var F:File;Var DirBuff:Dir_Buffer):Boolean;
- { schreibt Dir-Buffer einer Datei, und öffnet Datei }
-
- Function Find_in_Lib(Var LibFile:PathStr;Name:NameStr;Var E:Dir_Entry):Boolean;
- { sucht nach MACRO <Name> in LIB-Datei Libfile }
-
- Procedure CloseF(Var F :File);
-
- implementation
-
- Function Find_In_Dir(Name:NameStr;Var Verz:Dir_Table):Word;
- Var First,Last,Try :Word;
- begin
- Find_In_Dir:=0;
- Try:=0;
- First:=1;
- Last:=Verz[0].NrofDirEntries;
- UpStr(Name);
- While (First<=Last) Do { Binäre Suche im Sortierten Array }
- begin
- Try:=(First+Last) div 2;
- With Verz[Try] do
- begin
- If Name>Macroname then
- First:=Succ(Try)
- else
- If Name<Macroname then
- Last:=Pred(Try)
- else
- begin
- Find_In_Dir:=Try;
- Exit;
- end;
- end;
- end;
- end;
-
- Procedure CloseF(Var F :File);
- Var Dummy:Word;
- begin
- Inc(No_blink);
- Close(F);
- DummY:=IoResult;
- Dec(No_blink);
- end;
-
- Function Get_Dir_Buff(Var F:File;Var DirBuff:Dir_Buffer):Boolean;
- Var Dummy:Word;
- begin
- Get_Dir_Buff:=false;
- Inc(No_blink);
- Reset(F,Sizeof(BildElement));
- Dec(No_blink);
- If Ioresult<>0 then begin CloseF(F);Exit; end;
- Inc(No_blink);
- BlockRead(F,DirBuff,Succ(Dir_Header_Size));
- Dec(No_blink);
- If Ioresult<>0 then begin CloseF(F);Exit; end;
- IF DirBuff.DIR[0].FILEID<>LIB_FileID then
- begin CloseF(F); Exit; end;
- Get_Dir_Buff:=True;
- end;
-
- Function Put_Dir_Buff(Var F:File;Var DirBuff:Dir_Buffer):Boolean;
- Var Dummy:Word;
- begin
- Put_Dir_Buff:=false;
- Inc(No_blink);
- Reset(F,Sizeof(BildElement));
- Dec(No_blink);
- If Ioresult<>0 then begin CloseF(F);Exit; end;
- Inc(No_blink);
- BlockWrite(F,DirBuff,Succ(Dir_Header_Size));
- Dec(No_blink);
- If Ioresult<>0 then begin CloseF(F);Exit; end;
- Put_Dir_Buff:=True;
- end;
-
- Function Find_in_Lib(Var LibFile:PathStr;Name:NameStr;Var E:Dir_Entry):Boolean;
- Var V :Dir_buffer;
- F :File;
- Idx:Word;
- begin
- Find_In_Lib:=false;
- FillChar(E,Sizeof(E),0);
- Inc(No_blink);
- Assign(F,LibFile);
- If Get_Dir_Buff(F,V) then
- begin
- Idx:=Find_In_Dir(Name,V.DIR);
- If Idx>0 then
- begin
- E:=V.DIR[Idx];
- Find_In_Lib:=true;
- end;
- end;
- CloseF(F);
- Dec(No_blink);
- end;
-
-
-
- end.
-